//
//  MyTableViewController.m
//  WildDonkey
//
//  Created by 孙俊 on 15/4/7.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "MyTableViewController.h"
#import "MyTableViewCell.h"
#import "SDImageCache.h"
#import "DisclaimerViewController.h"

@interface MyTableViewController ()

@property (nonatomic,assign) CGFloat totalSize;
//菊花
@property (nonatomic,retain) UIActivityIndicatorView *activityIndicator;
@end

@implementation MyTableViewController

- (void)cleanTotal
{
	 NSLog(@"clean cache");
	[[SDImageCache sharedImageCache] clearDisk];
}

- (void)viewDidLoad {
    [super viewDidLoad];
   CGFloat X = [[SDImageCache sharedImageCache] getSize];
	
	self.totalSize += X / 1024.0 / 1024.0;
	NSLog(@"%.2f",self.totalSize);

	
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *cellIdentifier =@"reuseIdentifier";
	MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier	];
	if (nil == cell) {
		cell = [[MyTableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellIdentifier];
	}
	
	
	if (0 == indexPath.section) {
		cell.textLabel.text = @"个人中心正在建设中,敬请期待";
	}else if (1 == indexPath.section){
		cell.textLabel.text = @"清除缓存";
	}else{
		cell.textLabel.text = @"声明";
	}
	
	cell.selectionStyle = UITableViewCellSelectionStyleBlue;

    return cell;
}

//图片加载菊花
- (void)loading
{
	_activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleWhiteLarge)];
	self.activityIndicator.frame = CGRectMake(self.view.center.x - 20, self.view.center.y - 40, 30, 30) ;
	self.activityIndicator.center = CGPointMake(self.view.center.x, self.view.center.y - 30);
	self.activityIndicator.color = [UIColor grayColor];
	[self.view addSubview:self.activityIndicator];
	[self.activityIndicator startAnimating];
	
	
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	if (0 == indexPath.section) {
		NSLog(@"my");
	}else if (1 == indexPath.section){
		
		
		
			
			UIAlertController *clean = [UIAlertController alertControllerWithTitle:@"清除缓存" message:[NSString stringWithFormat:@"您将清除缓存%.2fM",self.totalSize] preferredStyle:(UIAlertControllerStyleAlert)];
			
			UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) {
				NSLog(@"Cancel");
				
			}];
			
			
			UIAlertAction *cleanAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
				[self cleanTotal];
				[self.tableView reloadData];
			}];
			
			[clean addAction:cancelAction];
			[clean addAction:cleanAction];
			
			[self presentViewController:clean animated:YES completion:nil];

	}else{
		
		DisclaimerViewController *disVC = [[DisclaimerViewController alloc] init];
		[disVC retain];
		[self.navigationController pushViewController:disVC animated:YES];
		
		[disVC release];
	}
	
}
//if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
//		}else
//		{
//			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清除缓存" message:[NSString stringWithFormat:@"您将清除缓存%.2fM",self.totalSize] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
//			
//			[alert show];
//			[self cleanTotal];
//			
//		}
		
		
		
		


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
